const jwt = require('jsonwebtoken');
const secretKey = 'your-secret-key'; // 实际应用中应该使用环境变量

// 创建token
exports.createToken = (data) => {
  return new Promise((resolve) => {
    const token = jwt.sign(
      data,
      secretKey,
      { expiresIn: '24h' }
    );
    resolve(token);
  });
};

// 验证token
exports.verifyToken = (token) => {
  return new Promise((resolve, reject) => {
    jwt.verify(token, secretKey, (err, decoded) => {
      if (err) {
        reject(err);
      } else {
        resolve(decoded);
      }
    });
  });
}; 